package com.example.testuser.controller;

import com.example.testuser.entity.TestUser;
import com.example.testuser.service.TestUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.ExecutionException;

@RestController
@RequestMapping(value = "/user")
public class UserController {

    private TestUserService userService;

    @Autowired
    public UserController(TestUserService userService) {
        this.userService = userService;
    }

    @GetMapping(value = "/getAllUser")
    public List<TestUser> getAllUser() {
        return userService.getAllUser();
    }

    @GetMapping(value = "/getUserByPk")
    public TestUser getUserByPk(String pkUser){
        return userService.getUserByPk(pkUser);
    }

    @GetMapping(value = "/getUserByCodeOrName")
    public TestUser getUserByCodeOrName(String code, String name){
        return userService.getUserByCodeOrName(code, name);
    }

    @PostMapping(value = "addOrUpdateUser")
    public String addOrUpdateUser(@RequestBody TestUser user) {
        userService.addOrUpdateUser(user);
        return "o";
    }

    @GetMapping(value = "deleteUserByPk")
    public String deleteUserByPk(String pkUser) {
        userService.deleteUserByPk(pkUser);
        return "o";
    }

    @GetMapping(value = "/findListMySql")
    public List<TestUser> findListMySql(String identity){
        return userService.findListMySql(identity);
    }

    @GetMapping(value = "/getAllStreamUser")
    public List<?> getAllStreamUser(){
        return userService.getAllStreamUser();
    }

    @GetMapping(value = "/getAllStreamUser1")
    public List<TestUser> getAllStreamUser1(){
        return userService.getAllStreamUser1();
    }

    @GetMapping(value = "/getAllStreamUser2")
    public List<TestUser> getAllStreamUser2(){
        return userService.getAllStreamUser2();
    }

    @GetMapping(value = "/readAllBy")
    public List<TestUser> readAllBy() throws ExecutionException, InterruptedException {
        return userService.readAllBy();
    }

}
